package ioperations;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-31
 * Time: 16:15
 */
public class BoorrowOperation implements IOperations{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入您要借阅的图书的名字：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.usedSize; i++) {
            if(bookList.books[i].getName().equals(name)) {
                if(bookList.books[i].isBorrowed()) {
                    System.out.println("该书已被借阅");
                    return;
                }
                bookList.books[i].setBorrowed(true);
                System.out.println("借阅成功");
                return;
            }
        }
        System.out.println("没有找到该图书");
    }
}
